<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root"></div>
    <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <script type="text/babel">
       
         class InputElement extends React.Component{
            constructor(props){
                super(props);
            }
            componentWillMount(){
                console.log("componentWillMount")
            }
            componentDidMount(){
                console.log("componentDidMount")
            }
            componentWillReceiveProps(newProps){
                console.log("componentWillReceiveProps,",this.props,newProps)
            }
            shouldComponentUpdate(newProps,newState){
                console.log("shouldComponentUpdate",newProps,newState);
                // shouldComponentUpdate方法通过返回boolean值来决定是否继续执行后面的生命周期
                // 该方法可以用来优化性能
                // 不能在shouldComponentUpdate、componentWillUpdate、componentDidUpdate、render
                // 这几个函数中调用setState来修改状态，否则会出现无限循环
                return true;
            }
            componentWillUpdate(){
                console.log("componentWillUpdate")
            }
            componentDidUpdate(){
                console.log("componentDidUpdate")
            }
            componentWillUnmount(){
                console.log("componentWillUnMount");
            }
            render(){
                console.log("render")
                return <div>
                    <label>{this.props.children}</label>    
                    <input  
                        type={this.props.type} 
                        onBlur={this.props.validate} 
                        value={this.props.value}
                        onInput={this.props.onInput}
                    />
                    <span>{this.props.info}</span>
                </div>
            }
        }
        class MyComponent extends React.Component{
            constructor(props){
                super(props);
                this.state = {
                    value:"你好"
                }
            }
         
            render(){
               
                return <div>
                        <input type="button" value="ok" onClick={this.handleClick}/>
                        <InputElement 
                            value={this.state.value}
                            onInput={(e) => this.setState({value:e.target.value})}
                        
                        >用户名：</InputElement>
                    </div>
            }
        }

        ReactDOM.createRoot(document.getElementById("root")).render(<MyComponent />);
    </script>
</body>
</html>